<?php
require_once 'includes/config.php';
require_once 'includes/functions.php';
require_once 'includes/class.phpmailer.php';
if(!empty($_POST['submit']))
{
$userName=$_REQUEST['userName'];
$password=$_REQUEST['password'];
$email=$_REQUEST['email'];
$firstName=$_REQUEST['firstName'];
$lastName=$_REQUEST['lastName'];
$address1=$_REQUEST['address1'];
$address2=$_REQUEST['address2'];
$address3=$_REQUEST['address3'];
$city=$_REQUEST['city'];
$state=$_REQUEST['state'];
$country=$_REQUEST['country'];
$zip=$_REQUEST['zip'];
$phoneNo=$_REQUEST['phoneNumber1']."-".$_REQUEST['phoneNumber2']."-".$_REQUEST['phoneNumber3'];
if(!empty($_REQUEST['extension']))
  $phoneNo.="-".$_REQUEST['extension'];
$currentDate=date("Y-m-d");
//$phoneNumber=$_REQUEST['phonenumber'];
$sqlSelUsr = "select * from tbl_users where username='".$userName."'";
$rstSelUsr = mysql_query($sqlSelUsr) or die(mysql_error());
$noSelUsr = @mysql_num_rows($rstSelUsr);
if($noSelUsr==0)
{
$sqlSelEmail = "select * from tbl_users where email='".$email."'";
$rstSelEmail = mysql_query($sqlSelEmail) or die(mysql_error());
$noSelEmail = @mysql_num_rows($rstSelEmail);
if($noSelEmail==0)
{
  $confirmCode=get_rand_id(14);
  $sqlInsTmpUsr="INSERT INTO tbl_temp_user SET   
  				 	username='".$userName."',
					password='".$password."',
					user_type=1,
					confirmation_code='".$confirmCode."',
					first_name='".$firstName."',
					last_name='".$lastName."',
					address_line_1='".$address1."',
					address_line_2='".$address2."',
					address_line_3='".$address3."',
					city='".$city."',
					zip='".$zip."',
					phone_number='".$phoneNo."',
					email='".$email."',
					status=1,
					created_date='".$currentDate."'";
	$rstInsTmpUsr = mysql_query($sqlInsTmpUsr) or die(mysql_error());
	$insertedId=mysql_insert_id();
	if($insertedId!='' && $insertedId>0)
	{
	$msg="<font face='Verdana, Arial, Helvetica, sans-serif' size='2'>
<table width='100%' border='0' bgcolor='#F8F8F8;font-size:10px'>
  <tr>
    <td width='2%'>&nbsp;</td>
    <td width='37%'><img src='http://genisofttechnologies.com/php1/swapen/images/logo.png' width='217' height='55' />      &nbsp;</td>
    <td width='61%'><h3>Complete your Swapen registration</h3></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan='2'><p>Hi <b>".$firstName." ".$lastName."</b>,
    </p>
    <p> Just click the below link to complete your registration. That's all there is to it. After that, you are ready to start using swapen.com</p>
    <p><a href='http://genisofttechnologies.com/php1/swapen/index.php?confirm&cnc=".$confirmCode."&usn=".$userName."'>http://genisofttechnologies.com/php1/swapen/index.php?confirm&cnc=".$confirmCode."&usn=".$userName."</a></p>
    <p>If the above link does not clickable, type in or copy and paste this link into your Web browser.</p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td height='40' colspan='2'>&nbsp;</td>
  </tr>
</table>
</font>";
		$mail = new PHPMailer(); // defaults to using php "mail()"
	  	$mail->MsgHTML($msg);
		$mail->From       = "mail@swapen.com";
		$mail->FromName   = "Swapen.com";
		$mail->Subject    = "Swapen sending you a confirmation code for registration";
		$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
		$mail->AddAddress($email, $firstName);
		$mail->Send();
	  $msg="successfully registered, Check your email for confirmation.";
	 }
	else
	  $msg="Problem in registration, Try again.";
}
else
	$msg="Same email already exist, enter any other email.";
}
else
 	$msg="Same username already exist, Choose any other username.";
}
?>
<div id='panel'>
<form name="frmRegisterMember" id="frmRegisterMember" method="post" action="<?php echo $_SERVER['php_self']?> " onsubmit="return validateRegisterMember()">
<input type="hidden" name="registerMemberKey" id="registerMemberKey" />
<table width="100%" border="0">
  <tr>
    <td width="35%" class="contentHeader"><h2>Register here for Swapen.com</h2></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" class="content">
      <tr  class="content">
        <td height="32" colspan="3"><div id="messageAreaTop"><?php if(isset($msg))
											echo "<font color='#FF0000'><b>".$msg."</b></font>";
										
		?></div></td>
        </tr>  
      <tr  class="content">
        <td width="35%"><div id="lblFirstName">First name</div>
            <input type="text" name="firstName" id="firstName"></td>
        <td width="31%"><div id="lblLastName">Last name</div>
          <input type="text" name="lastName" id="lastName"></td>
        <td width="34%">&nbsp;</td>
      </tr>
	  <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td colspan="2"><div id="lblAddress1">Address line 1</div><input type="text" name="address1" id="address1"></td>
        <td>&nbsp;</td>
      </tr>
      
      <tr>
        <td colspan="2"><input type="text" name="address2" id="address2"></td>
        <td>&nbsp;</td>
      </tr>
     <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblCity">City</div><input type="text" name="city" id="city"></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblCountry">Country</div><input type="text" name="country" id="country"></td>
        <td><div id="lblState">State/ Province</div><input type="text" name="state" id="state"></td>
        <td><div id="lblZip">Postal / zip code</div><input type="text" name="zip" id="zip"></td>
      </tr>
      <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td colspan="2"><div id="lblPhoneNumber">Phone number</div><input type="text" name="phoneNumber1" id="phoneNumber1" maxlength="4" size="3">&nbsp;/&nbsp;<input type="text" name="phoneNumber2" id="phoneNumber2" maxlength="4" size="3">&nbsp;/&nbsp;<input type="text" name="phoneNumber3" id="phoneNumber3" maxlength="6" size="4">&nbsp;&nbsp;&nbsp;Ext : <input type="text" name="extension" id="extension" maxlength="20" size="5"></td>
        <td>&nbsp;</td>
      </tr>
     <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblUserName">Username</div><input type="text" name="userName" id="userName"></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblPassword">Password</div><input type="password" name="password" id="password"></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblConfirmPassword">Enter password again</div><input type="password" name="confirmPassword" id="confirmPassword"></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblEmail">Email ID</div>
            <input type="text" name="email" id="email" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblEmailAgain">Enter Email Id again</div>
            <input type="text" name="emailAgain" id="emailAgain" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td><div id="lblSecurityCode">Security code</div>
						<img id="siimage" align="left" style="padding-right: 5px; border: 0" src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>" />
						
						<a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = 'securimage_show.php?sid=' + Math.random(); return false">
						<img src="images/reload.png" alt="Reload Image" border="0" onclick="this.blur()" align="bottom" /></a><input type="text" name="securityCode" id="securityCode"></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><input type="submit" name="submit" id="submit" value="Submit" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
       <tr>
        <td></td>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="3"><div id="messageAreaBottom"></div></td>
        </tr>
      <tr>
        <td></td>
        <td  height="10"></td>
        <td></td>
        <td></td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
</div>